package com.weirdor.douyin.utils;

import com.weirdor.douyin.DouYinStart;

import java.io.File;

/**
 * created by weirdor on 2018/5/25
 */
public class ResourceUtils {

    static final String ADB_PATH = "adb";

    public static String getHack(){
        String root = DouYinStart.class.getResource("/").getPath();
        File srcDir = new File(root, "imgs/input");
        srcDir.mkdirs();
        try {
            File file = new File(srcDir, "douyin" + ".png");
            if (file.exists()) {
                file.deleteOnExit();
            }
            Process process = Runtime.getRuntime().exec(ADB_PATH + " shell /system/bin/screencap -p /sdcard/screenshot.png");
            process.waitFor();
            process = Runtime.getRuntime().exec(ADB_PATH + " pull /sdcard/screenshot.png " + file.getAbsolutePath());
            process.waitFor();
            return file.getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
